package com.sright.bcard.common.service.share.utils;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by pengcheng091 on 2015/9/9 0009.
 */
public class CharsetUtils {
    public static final String UTF8 = "utf-8";

    public static String getFileCoding(InputStream bin) throws IOException {
        int p = (bin.read() << 8) + bin.read();
        String code = null;
        switch (p) {
            case 0xefbb:
                code = "UTF-8";
                break;
            case 0xfffe:
                code = "Unicode";
                break;
            case 0xfeff:
                code = "UTF-16BE";
                break;
            default:
                code = "GBK";
        }
        return code;
    }
}
